package com.example.demo.controller;

import com.example.demo.model.Clmana;
import com.example.demo.service.IClmanaService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author Administrator 张少婷
 */

    @Api(tags = "车辆管理")
    @RestController
    @RequestMapping("/swagger8")
    public class ClmanaController {
        @Autowired
        private IClmanaService clmanaService;
    @CrossOrigin
    @ApiOperation(value="对车辆信息的添加方法")
    @PostMapping("/insertClmana")
    public int insertClmana(@RequestBody Clmana clmana){
        System.out.println("进入添加车辆信息接口" );
        return clmanaService.insertClmana(clmana);
    }

    @PostMapping("/getAllClmana")
    public List<Clmana> getAllClmana(@RequestBody Clmana clmana)
    {
        System.out.println("进入查询方法");
        List<Clmana> listClmana=clmanaService.getAllClmana(clmana);
        return listClmana;
    }
    @PostMapping("/editClmana")
    public int EditClmana(@RequestBody Clmana clmana){
        System.out.println("添加修改方法");
        return clmanaService.updateClmana(clmana);
}
    @GetMapping("/delClmana")
    public int Delete(int cpid){
        System.out.println("进入删除方法");
        int returnValues=0;
        if(cpid!=0){
            Clmana clmana=new Clmana();
            clmana.setCpid(cpid);
        returnValues=clmanaService.deleteClmana(clmana);
        }
        return returnValues;
    }

    @GetMapping("/getOneClmana")
    public Clmana getAllClmana(int cpid){
        Clmana clmana=new Clmana();
        System.out.println("进入单条查询方法");
        if(cpid!=0){
            Clmana clmana1=new Clmana();
            clmana1.setCpid(cpid);
            clmana=clmanaService.getClmana(clmana1);
            System.out.println("返回的数据集合为:"+clmana.getCpid());
        }
        return clmana;
    }
}
